package com.hao.generator;

import com.hao.wms.domain.BaseDomain;
import com.hao.wms.domain.Employee;

import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.util.ArrayList;
import java.util.List;

public class ClassInfo {
    private String basePkg;
    private String className;
    private String objectName;
    private List<String> props = new ArrayList<>();

    public String getObjectName() {
        return objectName;
    }

    public String getBasePkg() {
        return basePkg;
    }

    public String getClassName() {
        return className;
    }

    public List<String> getProps() {
        return props;
    }

    public ClassInfo(Class<?> clazz) throws IntrospectionException {
        String pkg = clazz.getPackage().getName();
        basePkg = pkg.substring(0,pkg.lastIndexOf("."));
        className = clazz.getSimpleName();
        objectName = className.substring(0,1).toLowerCase()+className.substring(1);
        BeanInfo beanInfo = Introspector.getBeanInfo(clazz, BaseDomain.class);
        PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors();
        for (PropertyDescriptor pd : pds) {
            props.add(pd.getName());
        }

    }

}
